using System.Collections.Generic;
using Framework;
using UnityEngine;

public class ChatAI
{
    public ChatAI()
    {
        //https://open.bigmodel.cn/dev/api/http-call/http-auth
    }
    public void Send(string msg)
    {
        var task = GameEntry.HttpManager.Request("https://open.bigmodel.cn/api/paas/v4/chat/completions");
        task.Set(onResponse);
        task.AddHeader("Authorization", "Bearer 94b4d96a316a4fb7ac957fb95b595cb1.y2lU5q1CuKQsm9Az");
        task.AddHeader("Content-Type", "application/json");
        var d = new JsonData();
        d.messages.Add(new MsgData("user", msg));
        var str = Utils.Json.ToJson(d);
        task.AddJsonData(str);
        Debug.LogError(str);
    }
    private void onResponse(HttpResult result)
    {
        Debug.LogError(result.Text);
    }
}
class JsonData
{
    public string model;
    public List<MsgData> messages;
    public JsonData()
    {
        model = "glm-4-flash";
        messages = new();
    }

}
class MsgData
{
    public string role;
    public string content;
    public MsgData(string role, string content)
    {
        this.role = role;
        this.content = content;
    }
}